/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shoppingsystem.reports;

import com.shoppingsystem.data.AlmacenDatos;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

/**
 *
 * @author Usuario
 */
public abstract class Reporte {

    protected String nombre;
    protected String rutaRelativa;
    protected Map<String, Object> parametros;

    public Reporte() {
        this.parametros = new HashMap<>();
        this.parametros.put("TEST_PARAM", "HOLA");
    }

    @Override
    public String toString() {
        return nombre;
    }

    public void añadirParametro(String llave, Object valor) {
        parametros.put(llave, valor);
    }

    protected InputStream cargarFormato(String rutaRelativa) {
        return getClass().getResourceAsStream("jasper/" + rutaRelativa + ".jasper");
    }

    public JasperPrint generar() throws JRException {
        InputStream in = cargarFormato(rutaRelativa);
        return JasperFillManager.fillReport(in, parametros, AlmacenDatos.obtenerConexionJDBC());
    }

}
